// void, Obj This, point pt
{
	Hero this;
	Obj o;
	bool bSquadTarget;
	
	Sleep(10);
	this = This.AsHero();
	if(!.IsValid) return;
	//.pr("Hero::Patrol");
	//pr("hero patrol");
	.AddCommand(false, "patrol", .posRH);
	//.pr("Hero::patroling");
	{
		.FormSetupAndMoveTo(pt, 0, 0, true);
		// freeze patch
		if(!.HasPath()){
			Sleep(785);
			return;
		}
		
		while(.HasPath()){
			//.pr("Hero::moving");
			//.pr("Hero::Patrol::Looking for enemys");
			o = .BestTargetInSquadSight();
			
			if(o.IsValid){
				bSquadTarget = true;
				if(o.AsUnit.hero.IsValid)
					if(o.AsUnit.hero.command == "retreat_notai" ||
						o.AsUnit.hero.command == "retreat_bld_notai")
						bSquadTarget = false;
						
				//.pr("Hero::Patrol::Enemy Found, ATTACK!!!");
				if(bSquadTarget){
					while(o.IsValid){
						//.pr("Hero::patrol: Everybody attack now");
						//.army.SetCommand("idle");
						.army.SetCommand("advance", pt);
						
						while(!.GotoAttack(o, 1500, false, 15000)){
						
							o = .BestTargetInSquadSight();
							if(!o.IsAlive())
								break;
							if(o.AsUnit.hero.IsValid)
								if(o.AsUnit.hero.command == "retreat_notai" ||
									o.AsUnit.hero.command == "retreat_bld_notai")
									break;
						}
						//.pr("Hero::patrol: fighting");
						if (o.IsAlive && .IsValidTarget(o)){
							while(.Attack(o));
						}
						if(o.AsUnit.hero.IsValid)
							if(o.AsUnit.hero.command == "retreat_notai" ||
								o.AsUnit.hero.command == "retreat_bld_notai")
								break;
						o = .BestTargetInSquadSight();
					}
				}
				.FormSetupAndMoveTo(pt, 0, 0, true);
			}
			//.pr("Hero::Patrol::No Enemy");
			.FormKeepMoving (1500);
		}
    }
}
